package edu.nf.exam.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.exam.dao.ExamPaperInfoDao;
import edu.nf.exam.dao.impl.ExamPaperInfoDaoImpl;
import edu.nf.exam.entity.ExamPaperInfo;
import edu.nf.exam.exception.DataAcessException;
import edu.nf.exam.service.ExamPaperService;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试卷信息表--业务接口实现类
 */
public class ExamPaperServiceImpl implements ExamPaperService {
    /**
     * 添加
     * @param examPaperInfo
     */
    @Override
    public void checkAddExamPaper(ExamPaperInfo examPaperInfo) {
        ExamPaperInfoDao dao = new ExamPaperInfoDaoImpl();
        try {
            dao.addExamPaper(examPaperInfo);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new DataAcessException("添加失败");
        }
    }

    /**
     * 修改
     * @param examPaperInfo
     */
    @Override
    public void checkUpdateExamPaper(ExamPaperInfo examPaperInfo) {
        ExamPaperInfoDao dao = new ExamPaperInfoDaoImpl();
        try {
            dao.updateExamPaper(examPaperInfo);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new DataAcessException("修改失败");
        }
    }

    /**
     * 分页查询
     * @param examPaperName
     * @param paperType
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<ExamPaperInfo> checkQueryByTerm(String examPaperName,Integer paperType, String levelName, String subjectName, Integer pageNum, Integer pageSize) {
        //通过dao查询返回分页数据集合
        ExamPaperInfoDao dao = new ExamPaperInfoDaoImpl();
        List<ExamPaperInfo> list = dao.queryByTerm(examPaperName,paperType, levelName, subjectName, pageNum, pageSize);
        //封装为分页pageInfo对象
        PageInfo<ExamPaperInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 根据ID查询
     * @param examPaperId
     * @return
     */
    @Override
    public ExamPaperInfo checkQueryById(Integer examPaperId) {
        ExamPaperInfoDao dao = new ExamPaperInfoDaoImpl();
        try {
            return dao.queryExamPaperById(examPaperId);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("根据ID查询失败");
        }
    }


    /**
     * 多条件查询
     * @param examPaperInfo
     * @return
     */
    @Override
    public List<ExamPaperInfo> select(ExamPaperInfo examPaperInfo) {
        ExamPaperInfoDao dao = new ExamPaperInfoDaoImpl();
        try {
            List<ExamPaperInfo> list = dao.select(examPaperInfo);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("查询失败");
        }

    }
}
